import { nodeResolve } from '@rollup/plugin-node-resolve'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImportRollup from 'unplugin-auto-import/rollup'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'

export default defineConfig(({ mode }) => {
  return {
    publicDir: false,
    clearScreen: false,
    plugins: [
      vue(),
      vueJsx(),
      dts({
        // 自动复制d.ts
        copyDtsFiles: true,
        insertTypesEntry: true,
        outDir: 'dist/dts',
        include: ['./src', './index.ts', './auto-imports.d.ts'],
      }),
    ],
    build: {
      outDir: 'dist',
      minify: 'terser',
      assetsInlineLimit: 1024 * 100, // 小于100kb的静态资源打包时将内联为base64
      lib: {
        entry: './index.ts',
        name: 'fetm-hooks',
        formats: ['es'],
      },
      rollupOptions: {
        // 第三方库/样式取消打包, 在peerDependencies中加入了该依赖, 会自动引入
        external: ['@vueuse/core', 'element-plus', 'fetm-utils', 'vue'],
        output: {
          exports: 'named',
        },
        plugins: [
          nodeResolve(),
          // 自动导入vue等内部的相关函数
          AutoImportRollup({
            imports: ['vue', '@vueuse/core'],
            dts: './auto-imports.d.ts',
          }),
        ],
      },
    },
  }
})
